//
//  NetworkCommand.m
//  ZhangJiangJun
//
//  Created by FENGYL on 2017/1/18.
//  Copyright © 2017年 FENGYL. All rights reserved.
//

#import "NetworkCommand.h"
#import "UserModel.h"
#import "NSString+MD5.h"

#import <SVProgressHUD.h>
#import <AFNetworking.h>
#import <MBProgressHUD.h>

@implementation NetworkCommand

#pragma mark 登录
+(void)userLoginUserName:(NSString *)userName password:(NSString *)password success:(void(^)())success failure:(void(^)())failure{
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    parameters[NC_USER_GUID] = [self getUniqueStrByUUID];
    parameters[NC_TERMINAL_MODEL] = @"ffffffff";
    parameters[NC_PLAT_FORM] = @"IOS";
    parameters[NC_ACCOUNT_TYPE] = @1;
    parameters[NC_USER_NAME] = userName;
    
    NSString * newPassword = [NSString stringWithFormat:@"HYZ%@%@",userName,password];
    
    NSString * md5Password = [NSString stringToMD5:newPassword];
    
    parameters[NC_USER_PASSWORD] = md5Password;
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_DEBUG_LOGIN];
    
    NSLog(@"urlString:%@ , parameters:%@",postUrl,parameters);
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //登录失败
        
        //判断是否登录成功
        int idNumber = [[responseObject valueForKey:NC_USER_ID] intValue];
        
        NSString *tokenPass = [responseObject valueForKey:NC_TOKEN_PASS];
        
        int clientType = [[responseObject valueForKey:NC_CLIENT_TYPE] intValue];
        
        if (!(idNumber > 0) || !(tokenPass.length > 0) || !(clientType > 0)) {
            
            if (failure) {
                
                failure();
                
            }
            
            
            return;
            
        }
        
        //存返回信息
        UserModel * userModel = [[UserModel alloc]init];
        
        userModel.userID = [responseObject valueForKey:@"Id"];
        
        userModel.clientType = [responseObject valueForKey:@"ClientType"];
        
        userModel.tokenPass = [responseObject valueForKey:@"TokenPass"];
        
        userModel.userName = [responseObject valueForKey:@"UserName"];
        
        
        NSLog(@"success %@",responseObject);
        
        if (success) {
            
            success();
            
        }
        
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        if (failure) {
            
            failure();
            
        }
        
        
        
        
    }];
    
}

#pragma mark DebugLogin


#pragma mark 获取设备列表
+(void)getDeviceListSuccess:(void(^)())success failure:(void(^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_DEVICES_BY_ACCOUNT];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    
        
        userModel.deviceByAccountArray = responseObject;
        
        
        NSLog(@"success %@",responseObject);
        
        
        success();
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 历史报警
+(void)getHistoryEventDataByTime:(NSDate *)date serialNumber:(NSString *)serialNumber success:(void(^)())success failure:(void(^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    if (!serialNumber) {
        
        serialNumber = userModel.selectedDeviceSerialNumber;
        
    }
    
    //获取开始结束时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    
    NSString *stringDate = [dateFormatter stringFromDate:date];
    
    NSString *startTime = [NSString stringWithFormat:@"%@ 00:00:00",stringDate];
    
    NSString *endTime = [NSString stringWithFormat:@"%@ 23:59:59",stringDate];
    
    //
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    parameters[NC_SERIAL_NUMBER] = serialNumber;
    parameters[NC_START_TIME] = [self getTimeStampForDateString:startTime];
    parameters[NC_END_TIME] = [self getTimeStampForDateString:endTime];
    
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_HISTORY_EVENT_DATA_BY_TIME];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        userModel.deviceHistoryEventDataByTimeArray = responseObject;
        
        NSLog(@"success %@",responseObject);
        
        
        success();
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 上锁解锁
+(void)stampIsUnlock:(BOOL)isUnlock stampCount:(NSString *)stampCount time:(NSString *)time success:(void(^)())success failure:(void(^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    parameters[NC_SERIAL_NUMBER] = userModel.currentDeviceSerialNumber;
    
    if (isUnlock) {
        
        parameters[NC_COMMAND_TEXT] = [NSString stringWithFormat:@"*gzn*%@*%@*",stampCount,time];
        
    }else{
        
        parameters[NC_COMMAND_TEXT] = @"*gzn*0*";
        
    }
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_PUT_CHAT_COMMAND];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        
        
        NSLog(@"success %@",responseObject);
        
        
        success();
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 获取相应时间内设备警报经纬度
+(void)getDeviceLocationByTime:(NSDate *)date Success:(void (^)())success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    //获取开始结束时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"YYYY-MM-dd"];
    
    NSString *stringDate = [dateFormatter stringFromDate:date];
    
    NSString *startTime = [NSString stringWithFormat:@"%@ 00:00:00",stringDate];
    
    NSString *endTime = [NSString stringWithFormat:@"%@ 23:59:59",stringDate];
    
    //
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    parameters[NC_SERIAL_NUMBER] = userModel.currentDeviceSerialNumber;
    parameters[NC_START_TIME] = [self getTimeStampForDateString:startTime];
    parameters[NC_END_TIME] = [self getTimeStampForDateString:endTime];
    
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_HISTORY_TRACK_POI_DATA_BY_TIME];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        userModel.deviceHistoryEventLocationByTimeArray = responseObject;
        
        NSLog(@"success %@",responseObject);
        
        
        success();
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
}

#pragma mark 获取设备属性
+(void)getDeviceAttrsOfSuccess:(void (^)())success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [ NSMutableDictionary dictionary];
    
    NSMutableString *listSerialNumber = [NSMutableString string];
    
    //获取列表
    for (int i = 0; i < userModel.deviceByAccountArray.count; i++) {
        
        NSDictionary *dict = userModel.deviceByAccountArray[i];
        
        NSString *deviceSerialNumberString = [dict valueForKey:NC_SERIAL_NUMBER];
        
        if (i == 0) {
            
            [listSerialNumber appendString:deviceSerialNumberString];
            
        }else{
            
            [listSerialNumber appendString:[NSString stringWithFormat:@",%@",deviceSerialNumberString]];
            
        }
        
    }
    
    parameters[NC_LIST_SERIAL_NUMBER] = listSerialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_DEVICE_ATTRS];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        //分出icon
        NSMutableDictionary *iconDictionary = [NSMutableDictionary dictionary];
        
        for (NSDictionary *dict in responseObject) {
            
            NSString *iconUrl = [dict valueForKey:NC_ICON_URL];
            
            
            
            if (![iconUrl isKindOfClass:[NSNull class]]) {
                
                NSString *serialNumber = [dict valueForKey:NC_SERIAL_NUMBER];
                
                [iconDictionary setValue:iconUrl forKey:serialNumber];
                
            }
            
        }
        
//        userModel.deviceIconDictionary = iconDictionary;
        
        
        userModel.deviceAtrrsArray = responseObject;
        
        success();
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}



#pragma mark 批量获取最后状态信息

+(void)getLastStatusDataForSerialNumber:(NSString *)serialNumber Success:(void (^)(NSArray *responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    NSLog(@"usermodel %@",userModel.userID);
    
    parameters[NC_LIST_SERIAL_NUMBER] = serialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_LAST_STATUS_DATA];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 获取多个设备的最后数据点
+(void)getLastTrackPoiDataBySnsForSerialNumber:(NSString *)serialNumber Success:(void (^)(NSArray *responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[NC_LIST_SERIAL_NUMBER] = serialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_LAST_TRACK_POI_DATA_BY_SNS];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 获取单个设备的时间段数据
+(void)getHistoryTrackPoiDataByTimeForStartTime:(NSString *)startTime EndTime:(NSString *)endTime Success:(void (^)(NSArray *responseObject))success failure:(void (^)())failure{
    
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    NSNumber *startTimeNumber = [NetworkCommand getTimeStampForDateString:startTime];
    NSNumber *endTimeNumber = [NetworkCommand getTimeStampForDateString:endTime];
    
    parameters[NC_SERIAL_NUMBER] = userModel.selectedDeviceSerialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    parameters[NC_START_TIME] = startTimeNumber;
    parameters[NC_END_TIME] = endTimeNumber;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_HISTORY_TRACK_POI_DATA_BY_TIME];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];

    
}

#pragma mark 获取与此设备绑定的所有围栏
+(void)GetGeoFencesByDeviceForSerialNumber:(NSString *)serialNumber Success:(void (^)(NSArray *responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    if (!serialNumber) {
        
        serialNumber = userModel.selectedDeviceSerialNumber;
        
    }
    
    parameters[NC_SERIAL_NUMBER] = serialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_GET_GEO_FENCES_BY_DEVICE];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 提交围栏
+(void)PutGeoFenceForPoints:(NSString *)points fenceName:(NSString *)fenceName fenceId:(NSNumber *)fenceId Success:(void (^)(id responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[NC_POINTS] = points;
    parameters[NC_NAME] = fenceName;
    parameters[NC_TYPE] = @1;
    parameters[NC_PURVIEW] = @3;
    parameters[NC_FENCE_ID] = fenceId;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_PUT_GEO_FENCE];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 为设备绑定围栏
+(void)BindForBindFenceId:(NSNumber *)bindFenceId ZoneType:(NSNumber *)zoneType isEnter:(NSNumber *)isEnter isLeave:(NSNumber *)isLeave displayName:(NSString *)displayName serialNumber:(NSString *)serialNumber Success:(void (^)(id responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[NC_BIND_FENCE_ID] = bindFenceId;
    parameters[NC_ZONE_TYPE] = zoneType;
    parameters[NC_IS_ENTER] = isEnter;
    parameters[NC_IS_LEAVE] = isLeave;
    parameters[NC_DISPLAY_NAME] = displayName;
    parameters[NC_SERIAL_NUMBER] = serialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_BIND];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];

    
}

#pragma mark 为设备解除对某个围栏的绑定
+(void)UnBindForBindFenceId:(NSNumber *)bindFenceId ZoneType:(NSNumber *)zoneType isEnter:(NSNumber *)isEnter isLeave:(NSNumber *)isLeave displayName:(NSString *)displayName serialNumber:(NSString *)serialNumber Success:(void (^)(id responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[NC_BIND_FENCE_ID] = bindFenceId;
    parameters[NC_ZONE_TYPE] = zoneType;
    parameters[NC_IS_ENTER] = isEnter;
    parameters[NC_IS_LEAVE] = isLeave;
    parameters[NC_DISPLAY_NAME] = displayName;
    parameters[NC_SERIAL_NUMBER] = serialNumber;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_UN_BIND];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
    
}

#pragma mark 删除围栏
+(void)DelGeoFenceForPoints:(NSString *)points fenceName:(NSString *)fenceName fenceId:(NSNumber *)fenceId Success:(void (^)(id responseObject))success failure:(void (^)())failure{
    
    UserModel * userModel = [[UserModel alloc]init];
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[NC_POINTS] = points;
    parameters[NC_NAME] = fenceName;
    parameters[NC_TYPE] = @1;
    parameters[NC_PURVIEW] = @3;
    parameters[NC_FENCE_ID] = fenceId;
    parameters[NC_USER_ID] = userModel.userID;
    parameters[NC_CLIENT_TYPE] = userModel.clientType;
    parameters[NC_TOKEN_PASS] = userModel.tokenPass;
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    
    NSString * postUrl = [NSString stringWithFormat:@"%@%@",NC_SERVICE_URL,NC_DEL_GEO_FENCE];
    
    [manager POST:postUrl parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"success %@",responseObject);
        
        
        success(responseObject);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
        
        failure();
        
        
        
    }];
    
}

#pragma mark 时间戳转换NSDate
+(NSDate *)TimestampChangeDate:(NSString *)timestamp{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"HH:mm:ss"];
    
    NSLog(@"CurTimestamp =  %@",timestamp);
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
    
    return confromTimesp;
    
}

#pragma mark 时间戳转换时间(dd/MM/yyyy 23:59:59)
+(NSString *)getEndOfDayTimeStringForDate:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    
    NSString *stringDate = [dateFormatter stringFromDate:date];
    
    NSString *endTime = [NSString stringWithFormat:@"%@ 23:59:59",stringDate];
    
    return endTime;
    
}

#pragma mark 时间戳转换时间(HH:mm:ss)
+ (NSString *)TimestampChangeTimestr:(NSString *)Timestamp
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"HH:mm:ss"];
    
    NSLog(@"CurTimestamp =  %@",Timestamp);
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[Timestamp doubleValue]];
    NSLog(@"Greenwich time  = %@",confromTimesp);
    NSString *confromTimespStr = [dateFormatter stringFromDate:confromTimesp];
    NSLog(@"CurTime =  %@",confromTimespStr);
    return confromTimespStr;
}

#pragma mark 时间戳转换时间(dd/MM/yyyy HH:mm:ss)
+(NSString *)getTimeStringForTimeStamp:(NSNumber *)timeStamp{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
    
    NSLog(@"CurTimestamp =  %@",timeStamp);
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timeStamp doubleValue]];
    NSLog(@"Greenwich time  = %@",confromTimesp);
    NSString *confromTimespStr = [dateFormatter stringFromDate:confromTimesp];
    NSLog(@"CurTime =  %@",confromTimespStr);
    return confromTimespStr;
    
}

#pragma mark 根据日期和时间返回时间戳
+(NSNumber *)getTimeStampForDateString:(NSString *)dateString{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    NSLog(@"dateString %@",dateString);
    
    NSDate *date = [formatter dateFromString:dateString]; //------------将字符串按formatter转成nsdate
    
    NSLog(@"date %@",date);
    
    NSNumber * num = @([date timeIntervalSince1970]);
    
    NSLog(@"timeSp:%@",num); //时间戳的值
    
    
    return num;
}



#pragma mark 获取GUID
+ (NSString *)getUniqueStrByUUID
{
    CFUUIDRef    uuidObj = CFUUIDCreate(nil);//create a new UUID
    
    //get the string representation of the UUID
    
    NSString    *uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(nil, uuidObj);
    
    CFRelease(uuidObj);
    
    return uuidString ;
    
}


@end
